package com.sheng.sign.action;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;

import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven;
import com.sheng.sign.entity.Classes;
import com.sheng.sign.entity.Sign;
import com.sheng.sign.entity.Student;
import com.sheng.sign.service.ClassesService;
import com.sheng.sign.service.SignService;
import com.sheng.sign.service.StudentService;

public class SignAction extends ActionSupport implements ModelDriven<Sign>{

	
	/**
	 * 
	 */
	private static final long serialVersionUID = -7743327650328149371L;
	protected String forwardView;
	protected static final String allSign_list = "/page/allSign_add.jsp";
	protected static final String AllSign = "/page/allSign.jsp";
	protected static final String LIST_JSP = "/page/Signed_list.jsp";
	protected static final String allSignRandom_JSP = "/page/allSignRandom.jsp";
	
	private String courseName1;
	private List<Sign> lists ;
	private List<Sign> listes ;
	private List<Classes> ClassesList ;
	private List<Student> listss ;
	private Sign sign = new Sign();
	private Student student = new Student();
	private SignService signService;
	private StudentService studentService;
	private ClassesService classesService;
	
	//创建模型类实例getmodel()方法返回一个用于接收用户输入数据的对象模型
	//  getmodel()执行后会将department对象压入ValueStack值栈中
	public Sign getModel() {
		return sign;
	}
	/**
	 * 打开这个班的全部签到
	 * @Description:拦截打开进行签到动作，先选择班级和课程再显示这个班级的成员再进行签到
	 * @return
	 * String
	 * @exception:
	 * @author: huangshengjun 1532950421@qq.com
	 * @time:2019年12月7日 下午8:07:48
	 */
	public String openAllSign() {
		ClassesList = classesService.findAllList();//存取班级列表
		setForwardView(AllSign);
		return SUCCESS;
	}
	/**
	 * 打开这个班的随机签到，3个
	 * @Description:拦截打开进行签到动作，先选择班级和课程再显示这个班级的成员再进行签到
	 * @return
	 * String
	 * @exception:
	 * @author: huangshengjun 1532950421@qq.com
	 * @time:2019年12月7日 下午8:07:48
	 */
	public String openRandomSign() {
		ClassesList = classesService.findAllList();//存取班级列表
		setForwardView(allSignRandom_JSP);
		return SUCCESS;
	}
	/**
	 * 
	 * @Description:提交签到，进行签到情况的录入，签到状态值从前台来
	 * @return
	 * String
	 * @exception:
	 * @author: huangshengjun 1532950421@qq.com
	 * @time:2019年12月7日 下午8:06:43
	 */
	public String add() {
		Date date = new Date();
        //获取年月日
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");//可以方便地修改日期格式
        //获取时分秒
		String time = dateFormat.format(date); 
        System.out.println("===时间==="+time);
		for(int i=0;i<listes.size();i++) {
			listes.get(i).setCreateTime(time);
			listes.get(i).setCourseName(courseName1);
			System.out.println("=====courseName1==="+courseName1);
			listes.get(i).setIsDelete(0);
			signService.add(listes.get(i));
			System.out.println("===signAction输出==="+listes.get(i).getCourseName());
		}
		return this.list();
	}
	/**
	 * 
	 * @Description:点击查询班级和课程，返回
	 * @return
	 * String
	 * @exception:
	 * @author: huangshengjun 1532950421@qq.com
	 * @time:2019年12月7日 下午8:08:12
	 */
	public String listByClass() {
		listss = studentService.listByClass(student);
		setForwardView(allSign_list);
		return SUCCESS;
	}
	
	/**
	 * 
	 * @Description:查看考勤情况，搜索sign表信息返回
	 * @return
	 * String
	 * @exception:
	 * @author: huangshengjun 1532950421@qq.com
	 * @time:2019年12月7日 下午8:08:25
	 */
	public String list() {
		lists = signService.findAllList();
		setForwardView(LIST_JSP);
		return SUCCESS;
	}
	
	public List<Student> getListss() {
		return listss;
	}

	public void setListss(List<Student> listss) {
		this.listss = listss;
	}

	public Student getStudent() {
		return student;
	}

	public void setStudent(Student student) {
		this.student = student;
	}

	public String getForwardView() {
		return forwardView;
	}
	public void setForwardView(String forwardView) {
		this.forwardView = forwardView;
	}
	public List<Sign> getLists() {
		return lists;
	}
	public void setLists(List<Sign> lists) {
		this.lists = lists;
	}
	public Sign getSign() {
		return sign;
	}
	public void setSign(Sign sign) {
		this.sign = sign;
	}
	public SignService getSignService() {
		return signService;
	}
	public void setSignService(SignService signService) {
		this.signService = signService;
	}
	public StudentService getStudentService() {
		return studentService;
	}
	public void setStudentService(StudentService studentService) {
		this.studentService = studentService;
	}
	public List<Sign> getListes() {
		return listes;
	}
	public void setListes(List<Sign> listes) {
		this.listes = listes;
	}
	public List<Classes> getClassesList() {
		return ClassesList;
	}
	public void setClassesList(List<Classes> classesList) {
		ClassesList = classesList;
	}
	public ClassesService getClassesService() {
		return classesService;
	}
	public void setClassesService(ClassesService classesService) {
		this.classesService = classesService;
	}
	public String getCourseName1() {
		return courseName1;
	}
	public void setCourseName1(String courseName1) {
		this.courseName1 = courseName1;
	}
}
